/**
 * @file    flash_blob.c
 * @brief   Flash algorithm for the MAX32665
 *
 * DAPLink Interface Firmware
 *
 * Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Except as contained in this notice, the name of Maxim Integrated
 * Products, Inc. shall not be used except as stated in the Maxim Integrated
 * Products, Inc. Branding Policy.
 *
 * The mere transfer of this software does not imply any licenses
 * of trade secrets, proprietary technology, copyrights, patents,
 * trademarks, maskwork rights, or any other form of intellectual
 * property whatsoever. Maxim Integrated Products, Inc. retains all
 * ownership rights.
 *******************************************************************************
*/

#include "flash_blob.h"


const uint32_t flash_algo_blob[] = {
    0xE00ABE00, 0x062D780D, 0x24084068, 0xD3000040, 0x1E644058, 0x1C49D1FA, 0x2A001E52, 0x4770D1F2,
    0x2400b5f8, 0x4605460e, 0x0f0ff010, 0xf06fbf1c, 0xbdf80002, 0x5080f1a5, 0xf5b049fe, 0xd30a2f00,
    0x2000f5a0, 0xf5b04afc, 0xd3102f00, 0x5084f1a5, 0x4f80f5b0, 0x460cd201, 0xf1a5e00a, 0xf5a05084,
    0xf5b04080, 0xbf284f80, 0x0002f06f, 0x4614d201, 0x28002000, 0xbdf8bf18, 0x46284669, 0xfa6af000,
    0xbfb82800, 0x68a0bdf8, 0x0f07f010, 0xf06fbf18, 0xd10e0005, 0xf0106a60, 0xd0030f02, 0xf0206a60,
    0x62610102, 0xf02068a0, 0xf0404070, 0x60a15100, 0x28002000, 0xbdf8bf18, 0xf02068a0, 0x60a00010,
    0x60209800, 0x63206830, 0x63606870, 0x63a068b0, 0x63e068f0, 0xf04068a0, 0x60a00001, 0xf01068a0,
    0xd1fb0f07, 0xf02068a0, 0x60a04070, 0xf0106a60, 0xd0060f02, 0xf0206a60, 0x62600002, 0x0006f06f,
    0xf04fbdf8, 0x68014080, 0x0140f041, 0x68016001, 0x0f40f011, 0x2004d1fb, 0x0110f105, 0xbf8842a9,
    0x0080eb05, 0x6829d90a, 0x42916832, 0xf06fd002, 0xbdf80006, 0x1d361d2d, 0xd8f442a8, 0xbdf82000,
    0x45f0e92d, 0xb0872600, 0x1e704603, 0x90059600, 0x960148ba, 0x96039602, 0x6802460f, 0x46314635,
    0x6f00f412, 0x6800bf07, 0x5f80f410, 0x0006f06f, 0xbf18b007, 0x85f0e8bd, 0x0f03f013, 0xf06fbf1e,
    0xb0070002, 0x85f0e8bd, 0x1d1c4618, 0x0c01f04f, 0x4284aa05, 0xeb00bf88, 0xd90b0c8c, 0xf8d26804,
    0x45448000, 0xf06fd002, 0xe0030106, 0x1d121d00, 0xd8f34584, 0xbf1c0008, 0xe8bdb007, 0xf00385f0,
    0xf023080f, 0xf1aa0a0f, 0x499a5080, 0x2f00f5b0, 0xf5a0d30a, 0x4a982000, 0x2f00f5b0, 0xf1aad310,
    0xf5b05084, 0xd2014f80, 0xe00a460d, 0x5084f1aa, 0x4080f5a0, 0x4f80f5b0, 0xf06fbf28, 0xd2010002,
    0x20004615, 0xbf1c2800, 0xe8bdb007, 0xa90485f0, 0xf0004650, 0x2800f99f, 0xb007bfbc, 0x85f0e8bd,
    0xf01068a8, 0xbf180f07, 0x0005f06f, 0x6a68d10e, 0x0f02f010, 0x6a68d003, 0x0102f020, 0x68a86269,
    0x4070f020, 0x5100f040, 0x200060a9, 0xbf1c2800, 0xe8bdb007, 0x465485f0, 0x0010f10a, 0xbf384582,
    0xd2064669, 0x2b04f854, 0x2026f841, 0x42841c76, 0x9804d3f8, 0xf1b86028, 0xbf380f04, 0xd3099700,
    0x0f08f1b8, 0x9701bf38, 0xf1b8d304, 0xbf340f0c, 0x97039702, 0x46504669, 0xfec2f7ff, 0xe8bdb007,
    0x200085f0, 0x4a644b63, 0xb148e00a, 0xbf0c2801, 0x21004611, 0xf0116889, 0xd0030f07, 0x47702001,
    0xe7f74619, 0x28021c40, 0x2000dbef, 0x20004770, 0x20014770, 0xb4104770, 0xf04f2100, 0x4c554280,
    0xc154f8df, 0xb151e00b, 0xbf0c2901, 0x20004660, 0xf0136883, 0xd0040f07, 0x2001bc10, 0x46204770,
    0x6a43e7f6, 0x0f02f013, 0x6a43d003, 0x0302f023, 0x68836243, 0x4370f023, 0x5300f043, 0x68836083,
    0x437ff423, 0x432af443, 0x68836083, 0x0302f043, 0x68836083, 0x0f07f013, 0x6883d1fb, 0x4370f023,
    0x6a436083, 0x0f02f013, 0x6a41d006, 0x0102f021, 0xbc106241, 0x47702001, 0xf0406810, 0x60100040,
    0xf0106810, 0xd1fb0f40, 0x29021c49, 0xbc10dbbb, 0x47702000, 0xf1a0b5f8, 0x4e2e5180, 0x46024d2e,
    0x2f00f5b1, 0x4634d201, 0xf1a0e007, 0xf5a15180, 0xf5b12100, 0xd20b2f00, 0x4669462c, 0xf0004610,
    0x2800f8d9, 0x68a0bf04, 0x0f07f010, 0xe00dd10c, 0x5184f1a0, 0x4f80f5b1, 0xf1a2d3e5, 0xf5a05084,
    0xf5b04080, 0xd3e74f80, 0xbdf82001, 0xf0106a60, 0xd0030f02, 0xf0206a60, 0x62610102, 0xf02068a0,
    0xf0404070, 0x60a15100, 0xf42068a0, 0xf440407f, 0x60a040aa, 0x60209800, 0xf04068a0, 0x60a00004,
    0xe0202000, 0x2801b1f8, 0x4629bf0c, 0x68892100, 0x0f07f011, 0x1c40d1f4, 0xdbf32802, 0xf02068a0,
    0x60a04070, 0xf0106a60, 0xd00e0f02, 0xf0206a60, 0xe0050002, 0x40029000, 0x40029400, 0x40006c00,
    0x20016260, 0x4631bdf8, 0xf04fe7e1, 0x68014080, 0x0140f041, 0x68016001, 0x0f40f011, 0x2000d1fb,
    0xe92dbdf8, 0x461645f8, 0x4605460c, 0xf010466f, 0xd0270f03, 0x0003f025, 0x0a03f005, 0x0804f1ca,
    0x90006800, 0x0004f1c8, 0x46424438, 0xf0004631, 0xeba5f88c, 0x9900000a, 0xfe52f7ff, 0xbf182800,
    0x85f8e8bd, 0xeba44445, 0x44460408, 0x4628e00a, 0xf7ff6831, 0x2800fe45, 0xe8bdbf18, 0x1f2485f8,
    0x1d361d2d, 0xd3022c04, 0x0f0ff015, 0x2c10d1ef, 0x4631d30c, 0xf7ff4628, 0x2800fda3, 0xe8bdbf18,
    0x3c1085f8, 0x36103510, 0xd2f22c10, 0xd30c2c04, 0x68314628, 0xfe24f7ff, 0xbf182800, 0x85f8e8bd,
    0x1d2d1f24, 0x2c041d36, 0xb174d2f2, 0x90006828, 0x46314622, 0xf0004668, 0x4628f848, 0xf7ff6839,
    0x2800fe0f, 0xe8bdbf18, 0x200085f8, 0x85f8e8bd, 0xeb000889, 0x42810181, 0x6803d90a, 0xc000f8d2,
    0xd0014563, 0x47702001, 0x1d121d00, 0xd8f44281, 0x47702000, 0x5280f1a0, 0x2f00f5b2, 0xf3c0bf3c,
    0x60080012, 0xf1a0d31f, 0xf5a25280, 0xf5b22200, 0xbf3c2f00, 0x2000f5a0, 0x0012f3c0, 0xf1a0d312,
    0xf5b25284, 0xd3094f80, 0x4280f5a2, 0x4f80f5b2, 0xf5a0bf32, 0xf06f4080, 0x47700002, 0x000df3c0,
    0x2000f500, 0x20006008, 0xea404770, 0x079b0301, 0xe009d003, 0x1f12c908, 0x2a04c008, 0xe003d2fa,
    0x3b01f811, 0x3b01f800, 0xd2f91e52, 0x00004770, 0x00000000
};

/**
* List of start and size for each size of flash sector
* The size will apply to all sectors between the listed address and the next address
* in the list.
* The last pair in the list will have sectors starting at that address and ending
* at address start + size.
*/
static const sector_info_t sectors_info[] = {
    {0x10000000, 0x2000},
 };

const program_target_t flash = {
    0x200002a3, // Init
    0x200002cf, // UnInit
    0x200002d7, // EraseChip
    0x20000375, // EraseSector
    0x20000463, // ProgramPage
    0x20000531, // Verify

    // BKPT : start of blob + 1
    // RSB  : blob start + header + rw data offset
    // RSP  : stack pointer
    {
        0x20000001,
        0x200005d0,
        0x20000800
    },

    0x20000000 + 0x00000A00,               // program_buffer
    0x20000000,               // algo_start
    sizeof(flash_algo_blob),  // algo_size
    flash_algo_blob,          // image

    0x00002000   // ram_to_flash_bytes_to_be_written
};
